package cn.edu.lit.jsjxy.CourseExample.chapter4;

import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;

import cn.edu.lit.jsjxy.CourseExample.R;

public class DrawingActivity_4_4 extends Activity implements View.OnTouchListener
{
    TestView1 tView = null;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_drawing_4_4);

        tView = (TestView1) findViewById(R.id.testview1);
        tView.setOnTouchListener(this);


    }

    @Override
    public boolean onTouch(View view, MotionEvent motionEvent)
    {
        int x1, y1;
        switch (motionEvent.getAction()) {

            case MotionEvent.ACTION_DOWN:
                x1 = (int) motionEvent.getX();
                y1 = (int) motionEvent.getY();
                tView.setXY(x1, y1);
                //setContentView(tView);
                tView.invalidate();
                break;


            case MotionEvent.ACTION_MOVE:
                x1 = (int) motionEvent.getX();
                y1 = (int) motionEvent.getY();
                tView.setXY(x1, y1);
                //setContentView(tView);
                tView.invalidate();
                break;

            case MotionEvent.ACTION_UP:
//                x1 = (int) motionEvent.getX();
//                y1 = (int) motionEvent.getY();
//                tView.getXY(x1, y1);
//                //setContentView(tView);
//                tView.invalidate();
                break;

            case MotionEvent.ACTION_CANCEL:
                break;
            default:
                break;

        }


        return true;
    }


}
